#pragma once
#include <QGraphicsView>
#include <QWheelEvent>
#include <QMouseEvent>
#include <QWidget>
#include <QMenu>
#include <QPointF>

/**
 * BluePrintView - 蓝图画布视图（MVC中的View层）
 * 负责显示场景和处理用户交互（拖拽、缩放、右键菜单等）
 */
class BluePrintView : public QGraphicsView
{
    Q_OBJECT

public:
    explicit BluePrintView(QWidget *parent = nullptr);

signals:
    // 通知创建新节点的信号
    void requestCreateNode(const QString& nodeType, const QPointF& position);

protected:
    void wheelEvent(QWheelEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void drawBackground(QPainter *painter, const QRectF &rect) override;

    void contextMenuEvent(QContextMenuEvent *event) override;

private slots:
    void onCreateAddNode();  // 处理创建加法节点

private:
    void createContextMenu();    // 新增：创建右键菜单

private:
    bool m_isDragging = false;
    QPoint m_mousePressPos;      // 鼠标按下位置
    QPointF m_sceneCenterOnPress; // 按下时场景中心点

    QMenu *m_contextMenu;  // 右键菜单
    QPointF m_lastRightClickPos; // 最后一次右键点击位置
};